import PropTypes from 'prop-types'
import { useEffect, useState } from 'react'
import axios from '../../../utils/index'
import './Person.scss'
import { useNavigate } from 'react-router-dom'
Person.propTypes = {
    personId: PropTypes.array.isRequired,
    id: PropTypes.string.isRequired,
}

export default function Person(props) {
    let [info, setInfo] = useState(null)
    let navigate = useNavigate()
    useEffect(() => {
        axios.get(`/person/${props.personId}`).then(res => {
            setInfo(res.data[0])
        })
    }, [props.personId])
    return (
        <div className='person' onClick={() => {
            navigate(`/chat/${props.id}`, { state: { id: info?._id, username: info?.username } })
        }}>
            <div className='person-info'>
                <img src="http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg" alt="" />
                <div className='person-info-name'>
                    <h2>{info?.username}</h2>
                    <p>哈哈哈</p>
                </div>
            </div>
            <div>
                <p>{info?.intro ? info?.intro : '2024-5-30'}</p>
            </div>
        </div>
    )
}
